/*
 * @Descripttion: 创建一个患者（病人）
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-04-28 18:52:41
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-04-28 19:11:27
 */

const DB = require("../../lib/DB")
const { Success } = require("../../lib/Response")

module.exports = async function (ctx, next) {
    const { number, name, sex, age, memo, patient_type } = ctx.request.body
    try {
        const patient = await DB.models.patient.create({ number, name, sex, ages: age, memo, patient_type })
        ctx.body = new Success(patient.toJSON());
        await next();
    } catch (e) {
        console.error(e)
        throw new Error("创建患者失败")
    }
}
